/*
 * @Author: szx
 * @Date: 2022-03-21 15:39:46
 * @LastEditTime: 2022-03-21 15:57:45
 * @Description:
 * @FilePath: \leetcode\剑指offer\26\26.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} A
 * @param {TreeNode} B
 * @return {boolean}
 */
var isSubStructure = function (A, B) {
    if (!A || !B) return false;
    const dfs = (A, B, flag) => {
        if (!B) return true;
        if (!A) return false;
        if (A.val == B.val) {
            return dfs(A.left, B.left, true) && dfs(A.right, B.right, true);
        } else if (flag) {
            return false;
        }
        return dfs(A.left, B, false) || dfs(A.right, B, false);
    };
    return dfs(A, B);
};
